/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package xdxn.editor.studio.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Cai Han
 */
public class SqliteUtil {

    private final String CREATE_TABLE_IF_NO_EXIST = "CREATE TABLE IF NOT EXISTS ";

    private final String CREATE_EJECTOR_TABLE_SQL = CREATE_TABLE_IF_NO_EXIST //
            + "EJECTOR("
            + "id INT PRIMARY KEY,"
            + "descript TEXT)";

    private final String CREATE_BARRAGE_TABLE_SQL = CREATE_TABLE_IF_NO_EXIST //
            + "BARRAGE("
            + "id INT PRIMARY KEY,"
            + "start_index INT,"
            + "last_time INT,"
            + "speed FLOAT,"
            + "direction INT,"
            + "aspeed FLOAT,"
            + "aspeed_direction INT,"
            + "radius INT,"
            + "radius_direction INT,"
            + "sp_count INT," // 发射口数量，就是弹幕条数
            + "angle INT,"
            + "range INT,"
            + "aim INT,"// 0代表不瞄准，1代表瞄准
            // 以下为子弹部分
            + "bullet_speed FLOAT,"
            + "bullet_aspeed FLOAT,"
            + "bullet_aspeed_direction INT,"
            + "bullet_image_name,"
            // 关联字段
            + "ejector_id INT)";// 所属的发射器ID

    private final String CREATE_BARRAGE_EVENT_TABLE_SQL = "CREATE TABLE IF NOT EXISTS BARRAGE_EVENT("
            + "id INT PRIMARY KEY,"
            + "condition INT,"
            + "sign INT,"
            + "descript TEXT,"
            + "judge_value FLOAT,"
            + "result INT,"
            + "type INT,"
            + "style INT,"
            + "target FLOAT"
            + "change_time INT)";

    public SqliteUtil() {

        Connection conn = null;
        Statement stmt = null;

        try {
            Class.forName("org.sqlite.JDBC");
            conn = DriverManager.getConnection("jdbc:sqlite:data.db");
            stmt = conn.createStatement();
            stmt.executeUpdate(CREATE_EJECTOR_TABLE_SQL);
            stmt.executeUpdate(CREATE_BARRAGE_TABLE_SQL);
            stmt.close();
            conn.close();
        } catch (ClassNotFoundException | SQLException ex) {
            Logger.getLogger(SqliteUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void createTable() {

    }

}
